//
//  ZFK_postViewTableViewCell.m
//  Drops
//
//  Created by SHG on 16/5/30.
//  Copyright © 2016年 Drops.er. All rights reserved.
//

#import "ZFK_postViewTableViewCell.h"
#import "ZFK_postCollectionViewCell.h"
#import "UIKit+AFNetworking.h"

@implementation ZFK_postViewTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    ZFKFlowLayout *layout = [[ZFKFlowLayout alloc] init];
    layout.columnCounts = 2;
    layout.colunmSpace = 10;
    layout.rowSpace = 10;
    layout.edgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.delegate = self;
    
    self.mainCollectionView = [[UICollectionView alloc] initWithFrame:self.frame collectionViewLayout:layout];
//    NSLog(@"+++%f", self.frame.size.height);
    self.mainCollectionView.delegate = self;
    self.mainCollectionView.dataSource = self;
    self.mainCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.mainCollectionView];
    
    [self.mainCollectionView registerClass:[ZFK_postCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([ZFK_postCollectionViewCell class])];
    
    self.mainCollectionView.scrollEnabled = NO;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    NSLog(@"ttttttt:%ld", self.postArray.count);
    return self.postArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZFK_postCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([ZFK_postCollectionViewCell class]) forIndexPath:indexPath];
    ZFK_post *post = self.postArray[indexPath.row];
    cell.post = post;
    [cell.imageView setImageWithURL:[NSURL URLWithString:post.postImg]];
//    NSLog(@"[%@]", post.postImg);
    return cell;
}

- (CGFloat)layout:(ZFKFlowLayout *)layout heightForItemAtIndexPath:(NSIndexPath *)indexPath width:(CGFloat)width {
    ZFK_post *post = self.postArray[indexPath.row];
    CGFloat height = width * [post.postImgHeight floatValue] / [post.postImgWidth floatValue];
    return height;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"瀑布流点击:%ld", indexPath.row);
}

- (void)setPostArray:(NSMutableArray *)postArray {
    _postArray = postArray;
}

- (void)setPost:(ZFK_post *)post {
    _post = post;
}


@end
